<?php 
include_once("Service.php"); 
class ServiceModule extends Service
{
  private $strproid;
  public function create($arrParams)
  {
    if($arrParams=="")
    return json_encode(array("status"=>"err","msg"=>"参数不合法"));
    try
    {
      $this->sql = "insert into tbpromodule(strname,strdemo,strduty,dtexpect,strproid,ftrate,strmid,dtcreate,dtupdate,ftpercent) values(:strname,:strdemo,:strduty,:dtexpect,:strproid,:ftrate,:strmid,:dtcreate,:dtupdate,:ftpercent)";
      //get the max id
      $maxid = $this->db->getRecord("select case count(strmid) when 0 then 10001 else max(convert(strmid,signed))+1 end from tbpromodule");
      $arrParams[":strmid"] = $maxid[0];
      $arrParams[":dtcreate"] = date("Y/m/d");
      $arrParams[":dtupdate"] = $arrParams[":dtcreate"];
      $this->executeUpdate($arrParams);
      $this->clear();
      //return the json data
      return json_encode($arrParams);
      //return json_encode(array("status"=>"suc","strproid"=>$maxid[0]));
    }
    catch(Exception $ex)
    {
      return json_encode(array("status"=>"err","msg"=>$ex->getMessage()));
    }
  }
  public function queryMenu($count=5)
  {
    try
    {
      $this->sql = "select strproid,strname from tbproject order by dtcreate desc limit 0,".$count; 
      $res = $this->query(null,PDO::FETCH_ASSOC);
      $arrRes = array("status"=>"suc","projects"=>array());
      foreach($res as $row)
        array_push($arrRes["projects"],$row);
      $this->clear();
      return json_encode($arrRes);
    }
    catch(Exception $ex)
    {
      $this->clear();
      return json_encode(array("status"=>"err","msg"=>$ex->getMessage()));
    }
  }
  /**
   * get all the detail of modules
   */
  public function getDetails()
  {
    try
    {
      $this->sql = "select * from tbpromodule";
      $res = $this->query(null,PDO::FETCH_ASSOC);
      $arrRes = array("status"=>"suc","modules"=>$res);
      return json_encode($arrRes);
    }
    catch(Exception $ex)
    {
      return json_encode(array("status"=>"err","msg"=>$ex->getMessage()));
    }
    finally
    {
      $this->clear();
    }
  }
  public function getSum()
  {
    return json_encode(array("status"=>"suc","modules"=>array(array(75,1),array(20,2),array(42,3),array(71,4))));
    try
    {
      $this->sql = "SELECT month( dtcreate ) month , count( dtcreate ) count FROM `tbproject` WHERE year( dtcreate ) = year( now( ) ) GROUP BY month( dtcreate ) order by month(dtcreate)";
      $res = $this->query();
      $arrRes = array("status"=>"suc","line"=>array());
      for($i=1;$i<=12;$i++)
      array_push($arrRes["line"],array($i."月",$i));
      foreach($res as $row)
      {
        for($i=0;$i<count($arrRes["line"]);$i++)
        {
          if($row[0]==$arrRes["line"][$i][1])
          {
            $arrRes["line"][$i][1]=$row[1];
            break;
          }
        }
      }
      return json_encode($arrRes);
      $this->clear();
    }
    catch(Exception $ex)
    {
      $this->clear();
      return json_encode(array("status"=>"err","msg"=>$ex->getMessage()));
    }
  }
}
 ?>